package com.demo.dao;

import com.demo.dao.mapper.RposMapper;
import com.demo.utils.RandomUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class RposDao extends BaseDao {
    private static final String ENVIRONMENT_CU = "CU";
  
    public String selectPosNameByposID(String valueCode) {
        List<String> posNameList = null;
        String posName = null;

        try (SqlSession session = openSession(ENVIRONMENT_CU)){
        	RposMapper mapper = session.getMapper(RposMapper.class);
        	posNameList = mapper.selectPosNameByPosId(valueCode);
            posName = RandomUtil.randomResult(posNameList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return posName;
    }
    
    public BusinessInfo selectbusinessInfoByPosId(String valueCode) {
        List<BusinessInfo> businessInfoList = null;
        BusinessInfo businessInfo = null;

        try (SqlSession session = openSession(ENVIRONMENT_CU)){
        	RposMapper mapper = session.getMapper(RposMapper.class);
        	businessInfoList = mapper.selectbusinessInfoByPosId(valueCode);
            businessInfo = RandomUtil.randomResult(businessInfoList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return businessInfo;
    }

    public String selectSettingKey() {
        String settingKey = null;

        try (SqlSession session = openSession(ENVIRONMENT_CU)){
            RposMapper mapper = session.getMapper(RposMapper.class);
            settingKey = mapper.selectSettingKey();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return settingKey;
    }
}
